l_book_avail = [0,1,2,3,4]
l_book_used = []
l_like = [(2,3),(0,1,4),(1,2),(3),(1,4)]
def Try(i,j):
    global l_book_avail,l_book_used
    if i == 4 and l_like[i][j] not in l_book_avail:
        return
    print(i,type(i))
    if str(type(l_like[i])) == "<class 'int'>":    
        if l_like[i] in l_book_avail:
            l_book_avail[j] = -1
            if str(type(l_like[i])) == "<class 'int'>":
                l_book_used.append(l_like[i])
            else:
                l_book_used.apped(l_like[i][j])
    else:
        if l_like[i][j] in l_book_avail:
            l_book_avail[j] = -1
            if str(type(l_like[i])) == "<class 'int'>":
                l_book_used.append(l_like[i])
            else:
                l_book_used.append(l_like[i][j])
            
    if str(type(l_like[i])) == "<class 'int'>":
        Try(i + 1,0)
    elif i < len(l_like):
        Try(i + 1,0)
    else:
        Try(i,j + 1)
        
            
Try(0,0)
print(l_book_used)